import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';
export namespace PerBusinessFamilySupervisorApi {
  /** 人员境内主管业务信息 */
  export interface BusinessFamilySupervisor {
    id: number; // 主键ID
    busiId?: string; // 业务主表ID
    familySupervisorId: number; // 正式表ID，对应 per_family_supervisor.id，用于修改或删除时关联
    employeeId?: number; // 人员ID，对应 per_employee.id
    relation: string; // 与本人关系（称谓）
    systemPersonId: number; // 系统人员ID，对应 system_person.id
    familyName: string; // 姓名
    cardType: string; // 证件类型
    familyIdcard: string; // 证件号码
    cohabit: string; // 是否共同生活（是/否）
    companyName: string; // 企业名称
    countryRegion: string; // 国家
    branchAddress: string; // 分支机构地址
    position: string; // 所任职务
    status: number; // 记录状态（1：有效，0：无效）
    remarks: string; // 备注
    changeType: string; // 变更类型（add：新增，update：修改，delete：删除）
    changeContent: string; // 变更内容(JSON格式，仅修改时记录差异)
    auditStatus: number; // 审核状态（0 草稿 1 审核中 2 审核完成）
    finalAuditStatus: number; // 最终审核状态（0 待审核 1 审核通过 2 审核不通过）
    auditTime: string | Dayjs; // 审核完成时间
    auditor: string; // 审核人
    auditComment: string; // 审核意见
    metadata: string; // 其他参数
  }
}

/** 查询人员境内主管业务分页 */
export function getBusinessFamilySupervisorPage(
  data: PageParam,
  desensitize: boolean,
  encrypt: boolean,
) {
  return requestClient.post<
    PageResult<PerBusinessFamilySupervisorApi.BusinessFamilySupervisor>
  >('/per/business-family-supervisor/page', data, { desensitize, encrypt });
}

/** 查询人员境内主管业务详情 */
export function getBusinessFamilySupervisor(params: { id: number }) {
  return requestClient.get<PerBusinessFamilySupervisorApi.BusinessFamilySupervisor>(
    `/per/business-family-supervisor/get?id=${params.id}`,
  );
}

/** 新增人员境内主管业务 */
export function createBusinessFamilySupervisor(
  data: PerBusinessFamilySupervisorApi.BusinessFamilySupervisor,
) {
  return requestClient.post('/per/business-family-supervisor/create', data);
}

/** 修改人员境内主管业务 */
export function updateBusinessFamilySupervisor(
  data: PerBusinessFamilySupervisorApi.BusinessFamilySupervisor,
) {
  return requestClient.put('/per/business-family-supervisor/update', data);
}

/** 删除人员境内主管业务 */
export function deleteBusinessFamilySupervisor(params: { id: number }) {
  return requestClient.delete(
    `/per/business-family-supervisor/delete?id=${params.id}`,
  );
}

/** 批量删除人员境内主管业务 */
export function deleteBusinessFamilySupervisorList(ids: number[]) {
  return requestClient.delete(
    `/per/business-family-supervisor/delete-list?ids=${ids.join(',')}`,
  );
}

/** 导出人员境内主管业务 */
export function exportBusinessFamilySupervisor(params: any) {
  return requestClient.download(
    '/per/business-family-supervisor/export-excel',
    { params },
  );
}

/** 根据业务主表id去查询业务数据 */
export function getFamilySupervisorBusiId(data: any) {
  return requestClient.post<PerBusinessFamilySupervisorApi.BusinessFamilySupervisor>(
    '/per/business-family-supervisor/getFamilySupervisorBusiId',
    data,
  );
}

/** 获取当前登录人境内主管情况 */
export function getCurrentFamilySupervisor(
  data,
  desensitize: boolean,
  encrypt?: boolean,
) {
  return requestClient.post<
    List<PerBusinessFamilySupervisorApi.BusinessFamilySupervisor>
  >('/per/business-family-supervisor/getCurrentFamilySupervisor', data, {
    desensitize,
    encrypt,
  });
}
